package org.kymjs.emoji.control;

import org.kymjs.emoji.EmojiPageFragment;
import org.kymjs.emoji.KJEmojiFragment;
import org.kymjs.emoji.model.DisplayRules;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * 表情页适配器（FragmentPagerAdapter的好处是fragment常驻内存，对于要求效率而页卡很少的表情控件最合适）
 * 
 * @author kymjs
 * 
 */
public class EmojiPagerAdapter extends FragmentPagerAdapter {
    private final int type;

    public EmojiPagerAdapter(FragmentManager fm, int type) {
        super(fm);
        this.type = type;
    }

    @Override
    public Fragment getItem(int index) {
        return new EmojiPageFragment(index, type);
    }

    @Override
    public int getCount() {
        // 采用进一法取小数
        return (DisplayRules.getAllByType(type).size() - 1 + KJEmojiFragment.COUNT_IN_PAGE)
                / KJEmojiFragment.COUNT_IN_PAGE;
    }
}
